// components/shopCard/shopCard.js
Component({
  properties: {
    itemArr: {
      type: Array,
      value: []
    },
    isLoading: {
      type: Boolean,
      value: true
    },
    isFail: {
      type: Boolean,
      value: false
    },
    noLocationAuthor: {
      type: Boolean,
      value: false
    }
  },
  ready() {
    //获取urls
    this.setData({
      urls: getApp().globalData.urls
    })
    // console.log(this.data.itemArr)
  },
  /**
   * 组件的初始数据
   */
  data: {
    show_empty: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    enterShop(e) {
      //先判断用户是否是会员，会员才让进
      let index = e.currentTarget.dataset.index;
      //后续判断条件要改成 is_soldier 是否为 1
      if (wx.getStorageSync('userInfo').is_soldier === 1) {
        //保存店铺ID
        getApp().globalData.enterShopInfo = {
          shop_id: this.data.itemArr[index].shop_id,
          altitude: this.data.itemArr[index].address_altitude,
          latitude: this.data.itemArr[index].address_latitude,
        }
        wx.navigateTo({
          url: '/pages/shop/shop',
        })
      } else {
        wx.showModal({
          title: '温馨提示',
          content: '成为会员才能查看详情',
          cancelColor: '#BDBABE',
          confirmColor: "#FF325B",
          cancelText: '考虑一下',
          confirmText: '前往申请',
          success: (res) => {
            if (res.confirm) {
              wx.switchTab({
                url: '/pages/card/card',
              })
            }
          }
        })
      }
    },
    callShop(e) {
      // console.log(e.currentTarget.dataset.tel)
      let tel = e.currentTarget.dataset.tel;
      //联系商家
      wx.makePhoneCall({
        phoneNumber: tel,
      })
    },
    navShop(e) {
      let index = e.currentTarget.dataset.index;
      //导航到店
      wx.openLocation({
        latitude: parseFloat(this.data.itemArr[index].address_altitude),
        longitude: parseFloat(this.data.itemArr[index].address_latitude),
      })
    },
    iconError(e) {
      // console.log(e.currentTarget.dataset.index)
      let index = e.currentTarget.dataset.index
      this.setData({
        [`itemArr[${index}].iconError`]: true
      })
    }
  }
})